package com.liuyz.reader_;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class 缓冲字符输入流 {

    // 使用处理流一行一行的读取文件
    @Test
    public void read_1() {
        String path = "d:\\test.txt";
        BufferedReader bufferedReader = null;
        String line = "";
        try {
            // 构建处理流，传入节点流参数
            bufferedReader = new BufferedReader(new FileReader(path));
            while ((line = bufferedReader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != bufferedReader) {
                try {
                    // 关闭流时只需要关闭处理流，内部会调用节点流的close方法
                    bufferedReader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}
